package cn.autumnorange.app.common.provider.cacheannotation.filter;

import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;

public class MapRedissionFilter extends AbstractRedissionFilter {

    public MapRedissionFilter(RedissonClient redissonClient) {
        super("map",redissonClient);
    }

    /**
     * dataKey #分隔 获取指定redisson中的map 和map中的key
     * @param dataTypeString
     * @param dataKey
     * @return
     */
    @Override
    public Object doFilter(String dataTypeString,String dataKey) {
        if (this.getDataType().equalsIgnoreCase(dataTypeString)) {
            RedissonClient redissonClient =this.getRedissonClient();
            String[] dataKeySplit= dataKey.split("#");
            RMap rMap= redissonClient.getMap(dataKeySplit[0]);
            return rMap.get(dataKeySplit[1]);
        } else {
            return this.getNextRedissionFilter().doFilter( dataTypeString, dataKey);
        }
    }
}
